package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.ZsyyCourseVo;
import com.ruoyi.system.bo.ZsyyCourseQueryBo;
import com.ruoyi.system.bo.ZsyyCourseAddBo;
import com.ruoyi.system.bo.ZsyyCourseEditBo;
import com.ruoyi.system.service.IZsyyCourseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 产品分类Controller
 *
 * @author wangghua
 * @date 2021-07-14
 */
@ApiIgnore
@Api(value = "产品分类控制器", tags = {"产品分类管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/course")
public class ZsyyCourseController extends BaseController {

    private final IZsyyCourseService iZsyyCourseService;

    /**
     * 查询产品分类列表
     */
    @ApiOperation("查询产品分类列表")
    @PreAuthorize("@ss.hasPermi('system:course:list')")
    @GetMapping("/list")
    public TableDataInfo<ZsyyCourseVo> list(@Validated ZsyyCourseQueryBo bo) {
        return iZsyyCourseService.queryPageList(bo);
    }
    /**
     * 获取一级分类下拉列表
     */
    @ApiOperation("获取一级分类下拉列表")
    @GetMapping("/parentClassList")
    public AjaxResult parentClassList(@Validated ZsyyCourseQueryBo bo) {
        return AjaxResult.success(iZsyyCourseService.queryList(bo));
    }
    /**
     * 根据一级分类获取二级分类下拉列表
     */
    @ApiOperation("根据一级分类获取二级分类下拉列表")
    @GetMapping("/getListByParent")
    public AjaxResult getListByParent(@Validated ZsyyCourseQueryBo bo) {
        return AjaxResult.success(iZsyyCourseService.queryList(bo));
    }
    /**
     * 获取所有分类下拉列表
     */
    @ApiOperation("获取所有分类下拉列表")
    @GetMapping("/allClassList")
    public AjaxResult allClassList(@Validated ZsyyCourseQueryBo bo) {
        return AjaxResult.success(iZsyyCourseService.queryList(bo));
    }

    /**
     * 导出产品分类列表
     */
    @ApiOperation("导出产品分类列表")
    @PreAuthorize("@ss.hasPermi('system:course:export')")
    @Log(title = "产品分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ZsyyCourseVo> export(@Validated ZsyyCourseQueryBo bo) {
        List<ZsyyCourseVo> list = iZsyyCourseService.queryList(bo);
        ExcelUtil<ZsyyCourseVo> util = new ExcelUtil<ZsyyCourseVo>(ZsyyCourseVo.class);
        return util.exportExcel(list, "产品分类");
    }

    /**
     * 获取产品分类详细信息
     */
    @ApiOperation("获取产品分类详细信息")
    @PreAuthorize("@ss.hasPermi('system:course:query')")
    @GetMapping("/{id}")
    public AjaxResult<ZsyyCourseVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iZsyyCourseService.queryById(id));
    }

    /**
     * 新增产品分类
     */
    @ApiOperation("新增产品分类")
    @PreAuthorize("@ss.hasPermi('system:course:add')")
    @Log(title = "产品分类", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ZsyyCourseAddBo bo) {
        return toAjax(iZsyyCourseService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改产品分类
     */
    @ApiOperation("修改产品分类")
    @PreAuthorize("@ss.hasPermi('system:course:edit')")
    @Log(title = "产品分类", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody ZsyyCourseEditBo bo) {
        return toAjax(iZsyyCourseService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除产品分类
     */
    @ApiOperation("删除产品分类")
    @PreAuthorize("@ss.hasPermi('system:course:remove')")
    @Log(title = "产品分类" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iZsyyCourseService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
